<include file="Public:header" />
<include file="Public:left" />
<form  method="post" enctype="multipart/form-data" id="brandForm" name="brandForm">
    <section>
        <h2><strong>添加新闻</strong></h2>
        <ul class="ulColumn2">
            <li>
                <span class="item_name" style="width:120px;">新闻标题：</span>
                <input type="text" class="textbox textbox_295" name="title" id="title" placeholder="新闻标题..."/>
            </li>
            <li>
                <span class="item_name" style="width:120px;">部门：</span>
                <input type="text" class="textbox textbox_295" name="department" id="department" placeholder="部门...">
            </li>

            <li>
                <span class="item_name" style="width:120px;">新闻图片：</span>
                <input type="file" class="textbox textbox_295" name="picture" id="picture" placeholder="新闻图片..."/>
            </li>


            <li>
                <span class="item_name" style="width:120px;">是否要闻：</span>
                <select name="is_important" id="is_important">
                    <option value="1">是要闻</option>
                    <option value="0">非要闻</option>
                </select>
            </li>

            <li>
                <span class="item_name" style="width:120px;">是否发布：</span>
                <select name="is_display" id="is_display">
                    <option value="1">发布</option>
                    <option value="0">不发布</option>
                </select>
            </li>

            <li>
                <span class="item_name" style="width:120px;">发布时间：</span>
                <input type="text" class="textbox textbox_295" name="time" id="time" placeholder="发布时间..." value=""/>
            </li>
            <li>
                <span class="item_name" style="width:120px;">外链：</span>
                <input type="text" class="textbox textbox_295" name="link" id="link" placeholder="外链..." value=""/>
            </li>
            <li>
                <span class="item_name" style="width:120px;">所属分类：</span>
                <select name="category" id="category">
                    <volist name="category" id="vo">
                        <option value="{$vo.id}">{$vo.category_name}</option>
                    </volist>
                </select>
            </li>
            <li>
                <span class="item_name" style="width:120px;">排序：</span>
                <input type="text" class="textbox textbox_295" name="order_by" id="order_by" placeholder="排序..."/>
            </li>
            <li>
                <span class="item_name" style="width:120px;">新闻内容：</span>
                <script id="editor" name="content" type="text/plain" style="width:700px;height:300px;margin-left:125px; margin-top:-12px;"></script>
            </li>
            <li>
                <span class="item_name" style="width:120px;"></span>
                <input type="button" class="link_btn" value="提交"/>
            </li>
        </ul>
    </section>
</form>
<!--tabStyle-->
<script type="text/javascript" src="__STATIC__/laydate/laydate.js"></script>
<script>
    laydate.render({
        elem: '#time' //指定元素
        ,type:'datetime'
    });
</script>
<script type="text/javascript">
    $(document).ready(function(){
        //tab
        $(".admin_tab li a").click(function(){
            var liindex = $(".admin_tab li a").index(this);
            $(this).addClass("active").parent().siblings().find("a").removeClass("active");
            $(".admin_tab_cont").eq(liindex).fadeIn(150).siblings(".admin_tab_cont").hide();
        });

        $(".link_btn").click(function(){

            if($("#title").val()==""){
                layer.alert("新闻标题不能为空!");
                return false;
            }

            // if($("#department").val()==""){
            //     layer.alert("部门不能为空!");
            //     return false;
            // }

            // if($("#picture").attr("value")==""){
            //     layer.alert("新闻图片不能为空!");
            //     return false;
            // }


            // if($("#time").val()==""){
            //     layer.alert("创建时间不能为空!");
            //     return false;
            // }

            // if(ue.getContent()==""){
            //     layer.alert("新闻内容不能为空!");
            //     return false;
            // }

            var formData = new FormData();
            var title = $('input[name="title"]').val();
            var department = $('input[name="department"]').val();
            var is_important = $('select[name="is_important"]').val();
            var is_display = $('select[name="is_display"]').val();
            var time = $('input[name="time"]').val();
            var link = $('input[name="link"]').val();
            var order_by = $('input[name="order_by"]').val();
            var category = $('select[name="category"]').val();
            var content = ue.getContent();

            var file = $('input[name="picture"]');
            var fileObj = file.get(0).files[0];
//            console.log(fileObj);

            formData.append('title',title);
            formData.append('department',department);
            formData.append('picture',fileObj);
            formData.append('is_important',is_important);
            formData.append('is_display',is_display);
            formData.append('time',time);
            formData.append('link',link);
            formData.append('category',category);
            formData.append('content',content);
            formData.append('order_by',order_by);

            $.ajax({
                url:"{:url('Dynamic/add')}",
                type:'POST',
                data:formData,
                async:false,
                processData:false,
                contentType:false,
                success:function(result){
                    if(result.code == '0'){
                        layer.alert(result.msg);
                    }else{
                        layer.alert(result.msg, {
                                    btn: ['确定']
                                },
                                function (index, item) {
                                    location.href = result.url;
                                });
                    }
                }

            });

        });

    });
</script>

<script type="text/javascript">

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');


    function isFocus(e){
        alert(UE.getEditor('editor').isFocus());
        UE.dom.domUtils.preventDefault(e)
    }
    function setblur(e){
        UE.getEditor('editor').blur();
        UE.dom.domUtils.preventDefault(e)
    }
    function insertHtml() {
        var value = prompt('插入html代码', '');
        UE.getEditor('editor').execCommand('insertHtml', value)
    }
    function createEditor() {
        enableBtn();
        UE.getEditor('editor');
    }


</script>



</div>
</section>
</body>
</html>
